package com.beimi.game.module;

import com.beimi.game.player.GamePlayer;

public class GamePlayerModule {

	private int numPlayer;
	
	private GamePlayer[] players;
	
	public GamePlayerModule()
	{
		players = new GamePlayer[4];
	}

	public GamePlayer[] getPlayers() {
		return players;
	}

	public void addPlayer(GamePlayer player) {
		if (numPlayer >= 4) {
			return;
		}
		player.setSeat(numPlayer);
		players[numPlayer++] = player;
	}
	
	public int getNumPlayer() {
		return numPlayer;
	}

	public boolean hasOperations() {
		for (GamePlayer gamePlayer : players) {
			if (gamePlayer.getCardModule().hasOperation()) {
				return true;
			}
		}
		return false;
	}
	
	public void clearOperations() {
		for (int i = 0; i < players.length; i++) {
			GamePlayer gamePlayer = players[i];
			gamePlayer.getCardModule().clearOptions();
		}
	}
	
	public void broacastInRoom(String name, Object data, GamePlayer player) {
		
		for (int i = 0; i < players.length; i++) {
			GamePlayer gamePlayer = players[i];
			if (player != null && gamePlayer.getUserId() != player.getUserId()) {
				continue;
			}
			
			gamePlayer.sendMessage(name, data);
		}
	}

	public boolean hasCanHuPlayer(GamePlayer except) {
		for (int i = 0; i < players.length; i++) {
			GamePlayer gamePlayer = players[i];
			if (gamePlayer != except && gamePlayer.getCardModule().isCanHu()) {
				return true;
			}
		}
		return false;
	}
}
